﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Registration : System.Web.UI.Page
{
    private const String SUCCESS = "200";
    private const String DUPLICATE = "400";
    private const String EPIC_FAIL = "500";

    protected void Page_Load(object sender, EventArgs e)
    {
        //TODO: check if a session is already established, redirect if YES
        if ((Session["username"] != null) && (Session["username"].ToString().CompareTo("") != 0))
        {
            Response.Redirect("Default.aspx");
        }

        Result.Visible = false; //hide error message
    }

    protected void Register_Click(object sender, EventArgs e)
    {
        Result.Visible = false;

        String username = Username.Text;
        String email = Email.Text;
        String password = Password.Text;

        var Client = new BusinessTier.DataManipulation();
        String result = Client.CreateUser(username, password, email);

        switch (result)
        {
            case SUCCESS:
                Response.Redirect("Success.aspx");
                break;
            case DUPLICATE:
                Result.Text = "Too bad...someone got dibs on that username. Try again. :)";
                break;
            case EPIC_FAIL:
                Result.Text = "Don't worry. It's not you, it's us.";
                break;
            default:
                Result.Text = "How did you even get here?!";
                break;
        }
        Result.Visible = true; // display error
    }
}